{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import json\n",
    "from bokeh.plotting import figure, output_notebook, show\n",
    "import numpy as np\n",
    "from bokeh.charts.utils import cycle_colors\n",
    "import sweeper\n",
    "\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from IPython.display import display\n",
    "\n",
    "def plotLogs(log_names):\n",
    "    # parse log files, extracting json entry with stats per epoch and creating pandas DataFrame\n",
    "    frames = [pd.DataFrame(sweeper.loadLog('../logs/'+log+'/log.txt')) for log in log_names]\n",
    "    colors = ['red','blue','green','black','purple','orange','yellow']\n",
    "    \n",
    "    # this searches constant parameters across different runs to generate legends\n",
    "    legends = sweeper.generateLegends(frames)\n",
    "\n",
    "    # TODO: improve this, add hovers etc.\n",
    "    p = figure(title='test error', x_axis_label='epoch')\n",
    "    for i,frame in enumerate(frames):\n",
    "        p.line(frame['epoch'], 100-frame['test_acc'], color=colors[i], legend=legends[i])\n",
    "    show(p)\n",
    "    \n",
    "    p = figure(title='log loss', x_axis_label='epoch', y_axis_label='loss')\n",
    "    for i,frame in enumerate(frames):\n",
    "        p.line(frame['epoch'], np.log(frame['loss']), color=colors[i], legend=legends[i])\n",
    "    show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "plotLogs([\n",
    "    'nin_1875527964',\n",
    "    'vgg_24208029',\n",
    "    'resnet-pre-act_17934627',\n",
    "    'wide-resnet_1121914561'\n",
    "])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
